package cn.edu.ujn.lishlab3.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;

import cn.edu.ujn.lishlab3.dao.BaseDict;
import cn.edu.ujn.lishlab3.dao.BaseDictMapper;
import cn.edu.ujn.util.Page;

@Service("baseDictService")
@Transactional
public class BaseDictServiceImpl implements IBaseDictService{	
	@Autowired
	private BaseDictMapper baseDictDao;
	//类别代码查询数据字典
	public List<BaseDict> findBaseDictByTypeCode(String typecode) {
		List<BaseDict> selectBaseDictList = this.baseDictDao.selectBaseDictByTypeCode(typecode);
		return selectBaseDictList;
	}
	//123
	@Override
	public int deleteByPrimaryKey(int dictId) {
		// TODO Auto-generated method stub
		
		return 0;
	}
	@Override
	public int insert(BaseDict row) {
		// TODO Auto-generated method stub
		int insert = baseDictDao.insert(row);
		return insert;
	}
	@Override
	public int insertSelective(BaseDict row) {
		// TODO Auto-generated method stub
		List<BaseDict> list = this.baseDictDao.selectBaseDictByTypeCode(row.getDict_type_code());
		int num = list.size()+1;
		row.setDict_sort(num);
		int insertSelective = baseDictDao.insertSelective(row);
		return insertSelective;
	}
	@Override
	public BaseDict selectByPrimaryKey(int dictId) {
		// TODO Auto-generated method stub
		BaseDict selectByPrimaryKey = baseDictDao.selectByPrimaryKey(dictId);
		return selectByPrimaryKey;
	}
	@Override
	public int updateByPrimaryKeySelective(BaseDict row) {
		int updateByPrimaryKeySelective = baseDictDao.updateByPrimaryKeySelective(row);
		return updateByPrimaryKeySelective;
	}
	@Override
	public int updateByPrimaryKey(BaseDict row) {
		// TODO Auto-generated method stub
		int updateByPrimaryKey = baseDictDao.updateByPrimaryKey(row);
		return updateByPrimaryKey;
	}
	@Override
	public List<BaseDict> selectAll() {
		List<BaseDict> selectAll = baseDictDao.selectAll();
		return selectAll;
	}
	@Override
	public List<BaseDict> selectBaseDictList(BaseDict baseDict) {
		List<BaseDict> list = baseDictDao.selectBaseDictList(baseDict);
		return list;
	}
	@Override
	public Integer selectBaseDictListCount(BaseDict baseDict) {
		Integer count = baseDictDao.selectBaseDictListCount(baseDict);
		return count;
	}
	
	@Override
	public Page<BaseDict> findBaseDictList(Integer page, Integer rows, String baseDictName, String baseDictTypeName,String basedictTypeCode) {
		// TODO Auto-generated method stub
		BaseDict baseDict = new BaseDict();
        if(!StringUtils.isNullOrEmpty(basedictTypeCode)) {
        	baseDict.setDict_type_code(basedictTypeCode);
        }
        if(!StringUtils.isNullOrEmpty(baseDictName)) {
        	baseDict.setDict_item_name(baseDictName);
        }
		if(!StringUtils.isNullOrEmpty(baseDictTypeName)){
			baseDict.setDict_type_name(baseDictTypeName);
		}
		// 设置查询结果开始行数
		baseDict.setStart((page-1) * rows) ;
		// 设置查询结果返回条数
		baseDict.setRows(rows);
		// 执行分页查询
		List<BaseDict> baseDicts = this.baseDictDao.selectBaseDictList(baseDict);
		// 查询数据字典列表总记录数
		Integer count = this.baseDictDao.selectBaseDictListCount(baseDict);
		// 创建Page返回对象
		Page<BaseDict> result = new Page<BaseDict>();
		result.setPage(page);
		result.setRows(baseDicts);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}
	

}
